<template>
	<div class="g-doc">
		<div class="logo"></div>
		<form autocomplete="on">
			<label for="" id="count">
				<i class="count"></i><input type="text" maxlength="18" placeholder="输入账号" name="count" v-model="count">
				<b></b>
			</label>
			<label for="" id="password">
				<i class="psw"></i><input type="password" maxlength="18" placeholder="输入密码" name="passworld" v-model="psw"><b></b>
			</label>
			<a href="javascript:void(0);" class="login_btn" @click="is_null()">登录</a>
		</form>
	</div>
</template>

<script>
	import sha1 from '../../static/js/sha/sha1'
	import axios from 'axios'
	var Mock=require('mockjs');
	var storage=window.localStorage;
	var data=Mock.mock('login',{
		"code":200,
		"data":{
			"token":"abc"
		},
		"message":"success!"
	})
	
	export default{
		name:"login",
		data(){
			return{
				count:"",
				psw:""
			}
		},
		methods:{
			c_title(title){
				document.title = title;
				return this;
			},
			is_null(){
				var count=this.count,psw=this.psw;
				if(count.length==0||count==""){
					alert("请输入账号");
					return;
				}
				if(psw.length==0||psw==""){
					alert("请输入密码");
					return;
				}
				this.login();
			},
			login(){//登录操作
			var that=this;
			axios.get('login').then(function(res) {
			console.log(res);
			var data=res.data;
			if(data.code==200){
			storage.setItem("token", data.data.token);
				alert('登录成功！');
				//跳到首页
				that.$router.push({
			name:"home",path: '/'
	});
			}
	})
	return this;
	}
},
mounted() {
		this.c_title("登录");
		}
	}
</script>

<style scoped>
	@import url('../../static/css/login.css');
</style>